﻿Public Class FrmPeliculaWithDataGridView

    Private Sub PeliculaBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles PeliculaBindingNavigatorSaveItem.Click
        If Me.Validate() Then
            Me.PeliculaBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.VideoDataSet)
        End If
    End Sub

    Private Sub FrmPeliculaWithDataGridView_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'VideoDataSet.Alquiler' table. You can move, or remove it, as needed.
        Me.AlquilerTableAdapter.Fill(Me.VideoDataSet.Alquiler)
        GeneroComboBox.ComboBox.DataSource = GeneroBindingSourceForComboBox
        GeneroComboBox.ComboBox.DisplayMember = "nombre"
        GeneroComboBox.ComboBox.ValueMember = "id"
        Me.GeneroTableAdapter.Fill(Me.VideoDataSet.Genero)
        Me.PeliculaTableAdapter.Fill(Me.VideoDataSet.Pelicula)        
        FillPeliculasByGenero()
    End Sub

    Private Sub FillPeliculasByGenero()
        PeliculaBindingSource.Filter = "genero_id = " & CInt(GeneroComboBox.ComboBox.SelectedValue)
    End Sub

    Private Sub PeliculaDataGridView_DataError(sender As System.Object, e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles PeliculaDataGridView.DataError
        MessageBox.Show("Error en la fila " & e.RowIndex & ", columna " & e.ColumnIndex)
        e.Cancel = True
    End Sub

    Private Sub GeneroComboBox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles GeneroComboBox.SelectedIndexChanged
        FillPeliculasByGenero()
    End Sub

    Private Sub PeliculaDataGridView_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles PeliculaDataGridView.CellContentClick
        If e.ColumnIndex = 5 Then
            MessageBox.Show("Mostrar los alquileres de la película cuyo código de barras es: " & PeliculaDataGridView.Rows(e.RowIndex).Cells(0).Value.ToString())
        End If
    End Sub

End Class